//tab面板的切换
$('#xsps_tabs').tabs({
    border:false,
    onSelect:function (title) {
        if (title == "配送文本") {
            if (null == $("[name='xsps.id']").val() || $("[name='xsps.id']").val() == '') {
                $.messager.alert('提示', '请先配送销售单，才能打印配送单！', 'info');
                $('#xsps_tabs').tabs('select', "销售信息");
            } else {
                $.ajax({
                    type:"POST",
                    url:$.webPath() + '/wlgl/xsps/xsps_print_detail?xspsId=' + $("[name='xsps.id']").val(),
                    dataType:"html",
                    beforeSend:function () {
                        $.messager.progress();
                    },
                    success:function (data) {
                        $.messager.progress("close");
                        $('#xsps_content_id').html(data);
                    }
                });
            }
        }
    }
});

function xspsViewXsdglXshtDetail(id) {
    $.window({
        iconCls:'icon-tip',
        title:"详细信息",
        url:$.webPath() + "/htgl/xshtgl/xshtgl_detail?xshtId=" + id,
        width:1050,
        height:500,
        modal:true,
        isMax:false
    })
}

function xspsViewXsdglCgdDetail(id) {
    $.window({
        iconCls:'icon-tip',
        title:"详细信息",
        url:$.webPath() + "/cggl/cgdgl/cgdgl_detail?cgd.id=" + id,
        width:1050,
        height:500,
        modal:true,
        isMax:false
    })
}


$(function () {

    $("span.ljtip").ljDetail($("#xsps_xsd_detail_ljtip").val(), {
        position:'top'
    });

    $("#xsps_xsd_xsdmx_table").datagrid({
        url:$.webPath() + '/xsgl/xsdgl/xsdgl_xsmx?xsdId=' + $("#xsps_xsd_id").val(),
        fitColumns:false,
        singleSelect:true,
        fit:true,
        showFooter:true,
        rownumbers:true,
        columns:[
            [
                {field:'wzgg.oldcode', title:'老物资编码',align: 'center', width:100},
                {field:'wzgg.code', title:'物资编码',align: 'center', width:100},
                {field:'wzgg.name', title:'物资名称',align: 'center', width:100},
                {field:'wzgg.ggxh', title:'规格型号',align: 'center', width:100},
                {field:'wzgg.th', title:'图号',align: 'center', width:70},
                {field:'wzgg.dw', title:'单位',align: 'center', width:70},
                //{field: 'cd.z', title: '产地', width: 50},
                {field:'jzfs.z', title:'记重方式',align: 'center', width:70},
                {field:'kh.khbm', title:'卡号',align: 'center', width:130},
                {field:'xscb', title:'销售成本(元)',align: 'right', width:100, formatter:function (value) {
                    var sl = formatSl(value, ",");
                    return sl;
                }},
                {field:'js', title:'件数',align: 'right', width:70},
                {field:'sbsl', title:'数量',align: 'right', width:70,
                    formatter:function (value) {
                        var sl = formatSl(value, ",");
                        return sl;
                    }},
                {field:'hsj', title:'含税价(元)',align: 'right', width:100,
                    formatter:function (value) {
                        var sl = formatJe(value, ",");
                        return sl;
                    } },
                {field:'hse', title:'含税额(元)',align: 'right', width:100,
                    formatter:function (value) {
                        var sl = formatJe2(value, ",");
                        return sl;
                    } },
                {field:'bhsj', title:'不含税价(元)',align: 'right', width:100,
                    formatter:function (value) {
                        var sl = formatJe(value, ",");
                        return sl;
                    } },
                {field:'bhse', title:'不含税额(元)',align: 'right', width:100,
                    formatter:function (value) {
                        var sl = formatJe2(value, ",");
                        return sl;
                    } },
                {field:'cgd.cgdh', title:'采购单号',align: 'center', formatter:function (value, row) {
                    if (row['cgd.id']) {
                        return "<a style='color:red' href='javascript:void(0);' onclick='xspsViewXsdglCgdDetail(" + row['cgd.id'] + ")'>" + value + "</a>";
                    } else
                        return value;
                }, width:100},
                {field:'jsdh', title:'结算单号',align: 'center', width:150}

            ]
        ],
        loadFilter:function (data) {
            $.each(data.rows, function () {
                var bhsj = Math.round(this.bhsj * 10000) / 10000;
                var hsj = Math.round(this.hsj * 10000) / 10000;
                var sl = Math.round(this.sbsl * 10000) / 10000;

                if (this.bhsj) {
                    this.bhse = Math.round(multiply(sl, bhsj) * 100) / 100;
                }
                if (this.hsj) {
                    this.hse = Math.round(multiply(sl, hsj) * 100) / 100;
                }
            })
            return data;
        },
        onLoadSuccess:function(){
            $(".datagrid-htable .datagrid-cell").css('text-align', 'center');
        }
    })

    $('#xsps_yfsl').bind('click', function () {
        var yfsl = $('#xsps_yfsl_1').val();
        if (yfsl == 'on') {
            $("[name='yfsl']").hide();
            $('#xsps_yfsl_1').val('off');
        } else if (yfsl == 'off') {
            $("[name='yfsl']").show();
            $('#xsps_yfsl_1').val('on');
        }
    });

    $('#xsps_sfsl').bind('click', function () {
        var sfsl = $('#xsps_sfsl_1').val();
        if (sfsl == 'on') {
            $("[name='sfsl']").hide();
            $('#xsps_sfsl_1').val('off');
        } else if (sfsl == 'off') {
            $("[name='sfsl']").show();
            $('#xsps_sfsl_1').val('on');
        }
    });

    $('#xsps_kcdj').bind('click', function () {
        var kcdj = $('#xsps_kcdj_1').val();
        if (kcdj == 'on') {
            $("[name='kcdj']").hide();
            $('#xsps_kcdj_1').val('off');
        } else if (kcdj == 'off') {
            $("[name='kcdj']").show();
            $('#xsps_kcdj_1').val('on');
        }
    });

    $('#xsps_kcje').bind('click', function () {
        var kcje = $('#xsps_kcje_1').val();
        if (kcje == 'on') {
            $("[name='kcje']").hide();
            $('#xsps_kcje_1').val('off');
        } else if (kcje == 'off') {
            $("[name='kcje']").show();
            $('#xsps_kcje_1').val('on');
        }
    });

    $('#xsps_csdj').bind('click', function () {
        var csdj = $('#xsps_csdj_1').val();
        if (csdj == 'on') {
            $("[name='csdj']").hide();
            $('#xsps_csdj_1').val('off');
        } else if (csdj == 'off') {
            $("[name='csdj']").show();
            $('#xsps_csdj_1').val('on');
        }
    });

    $('#xsps_csje').bind('click', function () {
        var csje = $('#xsps_csje_1').val();
        if (csje == 'on') {
            $("[name='csje']").hide();
            $('#xsps_csje_1').val('off');
        } else if (csje == 'off') {
            $("[name='csje']").show();
            $('#xsps_csje_1').val('on');
        }
    });
});

function xsdpsyPrintPreview() {
    var LODOP = getLodop(document.getElementById('LODOP_OB_XSPS'), document.getElementById('LODOP_EM_XSPS'));
    LODOP.SET_PRINT_STYLEA(0, "NotOnlyHighPrecision", true);
    LODOP.PRINT_INIT("预览销售配送单");

    var strBodyStyle = "<style  type=\"text/css\">" +
        ".textcon{padding:8px;}" +
        ".input-tian{border-top:0 none;border-left:0 none;border-right:0 none;border-bottom: 1px solid black;height:22px;line-height:22px;width:100%;font-weight: bold;}" +
        " select{display:none}" +
        ".tb{width:auto;border-collapse:collapse;border-spacing:0;}" +
        ".tb th{padding:2px 2px 2px 12px;font-size:12px;font-weight:normal;text-align: right;}" +
        ".tb td{padding:2px;font-size:12px;}" +
        ".tb caption{ font-size:24px;height:60px;line-height:20px;}" +
        ".intb{width: 100%;}" +
        ".intb,.intb th,.intb td{border:1px solid black;}" +
        "</style>";
    var strFormHtmltops = strBodyStyle + "<div class='textcon'>" + document.getElementById("xsps_print_id").innerHTML + "</div>";
    var strFormHtmlbodys = strBodyStyle + "<div class='textcon'>" + document.getElementById("xsps_content_id").innerHTML + "</div>";
    var strFormHtmlBottoms = strBodyStyle + "<div class='textcon'>" + document.getElementById("xsps_detail_id").innerHTML + "</div>";

    LODOP.ADD_PRINT_TABLE(140, "1.5%", "90%", 350, strFormHtmlbodys);
    LODOP.SET_PRINT_STYLEA(0, "Vorient", 3);
    LODOP.ADD_PRINT_HTM(20, "1.5%", "90%", 145, strFormHtmltops);
    LODOP.SET_PRINT_STYLEA(0, "ItemType", 1);
    LODOP.SET_PRINT_STYLEA(0, "LinkedItem", 1);
    LODOP.ADD_PRINT_HTM(495, "1.5%", "90%", 200, strFormHtmlBottoms);
    LODOP.SET_PRINT_STYLEA(0, "ItemType", 1);
    LODOP.SET_PRINT_STYLEA(0, "LinkedItem", 1);
    LODOP.ADD_PRINT_TEXT(5, "80%", 135, 20, "总页号：第#页/共&页");
    LODOP.SET_PRINT_STYLEA(0, "ItemType", 2);
    LODOP.SET_PRINT_STYLEA(0, "Horient", 1);

    LODOP.PREVIEW();


}

